#ifndef CHEQUEFORM_TOUCH_H
#define CHEQUEFORM_TOUCH_H

#include <QWidget>
#include <QTableView>
#include <QTableWidget>
#include <QGridLayout>
#include <QLabel>
#include <QSqlQueryModel>
#include <QSerialPort>

#include "smartsortfilterproxymodel.h"
#include "interfaces.h"

#include "components/numpad.h"

class ChequeForm_Touch : public FormInterface
{
    Q_OBJECT
    
public:
    explicit ChequeForm_Touch(const QString &params, QWidget *parent = 0);
    ~ChequeForm_Touch();

    enum NpadMode {
        NpadNormalReading,
        NpadBarcodeReading,
        NpadQtyReading,
        NpadPriceReading
    };

public:
    void addGoods(int GOODS_ID, double kol_add);

    bool isBusy(){return goodsTable->rowCount()!=0;}
    bool isSystem(){return false;}
public slots:
    void on_goodsTable_cellChanged(int row, int column);
    void on_goodsTable_cellClicked(int row, int column);
    void on_npad_textChanged(const QString &text);
    void on_npad_textCommited(const QString &text);
    void on_searchTable_elementSelected(QModelIndex mi);
    void on_barcode_readyRead();
    void on_goodsTable_currentCellChanged(int,int,int,int);
    void selectGoods(const QString &params);
    void on_btCommit_clicked();
    void reconnectDevices();
signals:
    void chequeCommited();
private:
    void addSumm(double summ_add);

    NpadMode npadMode;

    Numpad *npad;

    QTableWidget *goodsTable;
    QTableView *searchTable;
    QSqlQueryModel *searchModel;
    SmartSortFilterProxyModel *searchProxy;
    QWidget *goodsSelector;

    QSerialPort *serial;

    QLabel *summField;
    QLabel *lastAction;

    QString params;
protected:
    bool eventFilter(QObject *obj, QEvent *event);
};

#endif // CHEQUEFORM_TOUCH_H
